import request from '@neu/biz-core/utils/request'

export const list = () => {
  return request({
    url: '/cmdb/bizdefs',
    method: 'get'
  })
}

export const page = (params) => {
  return request({
    url: '/cmdb/bizdefs/page',
    params,
    method: 'get'
  })
}

export const remove = (id) => {
  return request({
    url: '/cmdb/bizdefs/' + id,
    method: 'delete'
  })
}

export const update = (id, data) => {
  return request({
    url: '/cmdb/bizdefs/' + id,
    data: data,
    method: 'put'
  })
}

export const create = (data) => {
  return request({
    url: '/cmdb/bizdefs',
    data: data,
    method: 'post'
  })
}

export const detail = (id) => {
  return request({
    url: '/cmdb/bizdefs/' + id,
    method: 'get'
  })
}

export const getIcon = (bizdefId) => {
  return request({
    url: '/cmdb/bizdefs/' + bizdefId + '/icon',
    method: 'get'
  })
}

export const uploadIcon = (bizdefId) => {
  return '/cmdb/bizdefs/' + bizdefId + '/icon'
}

export const getRelations = (bizdefId) => {
  const url = '/cmdb/bizdefs/' + bizdefId + '/relations'
  return () => {
    return request({
      url: url,
      method: 'get'
    })
  }
}

export const addRelation = (bizdefId, data) => {
  return request({
    url: '/cmdb/bizdefs/' + bizdefId + '/relations/add',
    data,
    method: 'put'
  })
}

export const removeRelation = (bizdefId) => {
  const urlPrefix = '/cmdb/bizdefs/' + bizdefId + '/relations/'
  return (relationId) => {
    const url = urlPrefix + relationId
    return request({
      url: url,
      method: 'delete'
    })
  }
}

export const getTopo = (bizdefId) => {
  return request({
    url: '/cmdb/bizdefs/' + bizdefId + '/topo',
    method: 'get'
  })
}

